/* Copyright 2008 Bas van den Berg
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "yaffut.h"
#include "myassert.h"

#include "StringBuilder.h"


using namespace Chronos;
using namespace std;

struct StringBuilderTest {
    StringBuilder builder;
    StringBuilderTest() {
        builder << "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ";
        builder.clear();
    }
};


TEST(StringBuilderTest, testInitial) {
    ASSERT_TRUE(builder.isEmpty());
    ASSERT_EQUAL(0, builder.size());
    ASSERT_STR_EQUAL("", builder);
}

TEST(StringBuilderTest, testCharPointer) {
    builder << "Hello world.";
    ASSERT_FALSE(builder.isEmpty());
    ASSERT_EQUAL(12, builder.size());
    ASSERT_STR_EQUAL("Hello world.", builder);
}

TEST(StringBuilderTest, testClear) {
    builder << "Hello world.";
    builder.clear();
    ASSERT_TRUE(builder.isEmpty());
    ASSERT_EQUAL(0, builder.size());
    ASSERT_STR_EQUAL("", builder);
}

TEST(StringBuilderTest, testInt) {
    int num = -1234567;
    builder << num;
    ASSERT_FALSE(builder.isEmpty());
    ASSERT_EQUAL(8, builder.size());
    ASSERT_STR_EQUAL("-1234567", builder);
}

TEST(StringBuilderTest, testUnsignedInt) {
    unsigned int num = 1234567;
    builder << num;
    ASSERT_FALSE(builder.isEmpty());
    ASSERT_EQUAL(7, builder.size());
    ASSERT_STR_EQUAL("1234567", builder);
}

TEST(StringBuilderTest, testString) {
    string str = "Hello world.";
    builder << str;
    ASSERT_FALSE(builder.isEmpty());
    ASSERT_EQUAL(12, builder.size());
    ASSERT_STR_EQUAL("Hello world.", builder);

}

TEST(StringBuilderTest, testChar) {
    builder << '\n';
    ASSERT_FALSE(builder.isEmpty());
    ASSERT_EQUAL(1, builder.size());
    ASSERT_STR_EQUAL("\n", builder);
}

TEST(StringBuilderTest, testStringBuilder) {
    StringBuilder builder2;
    builder2 << "Hello world.";
    builder << builder2;
    ASSERT_FALSE(builder.isEmpty());
    ASSERT_EQUAL(12, builder.size());
    ASSERT_STR_EQUAL("Hello world.", builder);
}

TEST(StringBuilderTest, testConcatenation) {
    string str = "string. ";
    int num = -10;
    const char* str2 = " char pointer.";
    char enter = '\n';    
    builder << str << num << str2 << enter;
    ASSERT_FALSE(builder.isEmpty());
    ASSERT_EQUAL(26, builder.size());
    ASSERT_STR_EQUAL("string. -10 char pointer.\n", builder);
}

